home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Libraries
/
MacTCP class library
/
MacTCP class headers
/
CTCP.h
< prev
next >
Wrap
Text File
|
1992-10-26
|
17KB
|
512 lines
/*
CTCP.h
Superclass: CMacTCPDriver
The TCP implementation (Chapter 4, MacTCP Programmer's Guide).
Copyright © NCSA, University of Illinois; June 2, 1992
Eric Johnson, John Newlin and Igor Livshits
This code may be used, modified, and distributed free of charge and obligation.
*/
#define _H_CTCP // Include this file only once
#include "CMacTCPDriver.h" // Superclass definitions
#ifndef __TYPES__
#include <Types.h>
#endif
#define NumOfHistoBuckets 7 // Number of histogram buckets
#define TCPRcvBfrReturn 36 // Overwrites TCPBfrReturn (only in Chapter 4)
#define TCPCtlMax 49 // TCP specific (only in Chapter 4)
#define ipctlGetAddr 15 // Command code to get local IP address
#define BYTES_16WORD 2 // Bytes per 16 bit ip word
#define BYTES_32WORD 4 // Bytes per 32 bit ip word
#define BYTES_64WORD 8 // Bbytes per 64 bit ip word
#define kNameLength 50 // Default name length
#define kinDataLength 1024 // Default input data length
#define kOutDataLength 1024 // Default output data length
#define kStreamLength 8192 // Minimum stream length
#define kDefaultFlags 0xc0 // Default validity flags
#define kDefaultAction 0x01 // Default timout action
#define kEOL 0x00 // End of line marker
typedef enum TCPEventCode
{ // TCP events (p.48)
TCPClosing= 1,
TCPULPTimeout,
TCPTerminate,
TCPDataArrival,
TCPUrgent,
TCPICMPReceived,
lastEvent= 65535
};
typedef enum TCPTerminationReason
{ // TCP termination reasons (p.49)
TCPRemoteAbort= 2,
TCPNetworkFailure,
TCPSecPrecMismatch,
TCPULPTimeoutTerminate,
TCPULPAbort,
TCPULPClose,
TCPServiceError,
lastReason= 65535
};
typedef struct ip_addrbytes
{ // Accommodates numeric and string-type addresses
union
{
b_32 addr;
char byte[4];
} a;
} ip_addrbytes;
typedef struct wdsEntry
{ //
unsigned short length; // Length of buffer
char* ptr; // Pointer to buffer
} wdsEntry;
typedef struct rdsEntry
{
unsigned short length; // Length of buffer
char* ptr; // Pointer to buffer
} rdsEntry;
typedef unsigned long BufferPtr; // Our buffer
typedef unsigned long StreamPtr; // Our stream
typedef enum ICMPMsgType
{ // Responses
netUnreach,
hostUnreach,
protocolUnreach,
portUnreach,
fragReqd,
sourceRouteFailed,
timeExceeded,
parmProblem,
missingOption,
lastICMPMsgType= 65535
} ICMPMsgType;
typedef struct ICMPReport
{ // Connection report
StreamPtr streamPtr;
ip_addr localHost;
ip_port localPort;
ip_addr remoteHost;
ip_port remotePort;
enum ICMPMsgType reportType;
unsigned short optionalAddlInfo;
unsigned long optionalAddlInfoPtr;
} ICMPReport;
typedef pascal void (*TCPNotifyProc) // Notification routine
( StreamPtr tcpStream, // Our stream
unsigned short eventCode, // Which event
Ptr userDataPtr, // Custom data
unsigned short terminReason, // Terminatioon code
struct ICMPReport* icmpMsg // Status report
);
typedef void (*TCPIOCompletionProc) // Completion routine
( struct TCPiopb* iopb // Parameter block
);
enum
{ // Validity bit flags
timeoutValue= 0x80,
timeoutAction= 0x40,
typeOfService= 0x20,
precedence= 0x10
};
enum
{ // TOS flags
lowDelay= 0x01,
throughPut= 0x02,
reliability= 0x04
};
/*=====================*/
/*===---------------===*/
typedef struct HistoBucket
{ // A histogram bucket
unsigned short value; //
unsigned long counter; // Number of buckets
};
/*===---------------===*/
typedef struct TCPConnectionStats
{ // Connection statistics
unsigned long dataPktsRcvd; // Packets received
unsigned long dataPktsSent; // Packets sent
unsigned long dataPktsResent; // Packets resent
unsigned long bytesRcvd; // Byte flow info
unsigned long bytesRcvdDup; //
unsigned long bytesRcvdPastWindow; //
unsigned long bytesSent; //
unsigned long bytesResent; //
unsigned short numHistoBuckets; // Number of histogram buckets
struct HistoBucket sentSizeHisto[NumOfHistoBuckets];
unsigned short lastRTT; //
unsigned short tmrSRTT; //
unsigned short rttVariance; //
unsigned short tmrRTO; //
byte sendTries; //
byte sourchQuenchRcvd; //
}TCPConnectionStats;
/*===---------------===*/
typedef struct TCPParam
{ // TCP parameters
unsigned long tcpRtoA;
unsigned long tcpRtoMin;
unsigned long tcpRtoMax;
unsigned long tcpMaxSegSize;
unsigned long tcpMaxConn;
unsigned long tcpMaxWindow;
}TCPParam;
/*===---------------===*/
typedef struct TCPStats
{ // TCP statistics
unsigned long tcpConnAttempts;
unsigned long tcpConnOpened;
unsigned long tcpConnAccepted;
unsigned long tcpConnClosed;
unsigned long tcpConnAborted;
unsigned long tcpOctetsIn;
unsigned long tcpOctetsOut;
unsigned long tcpOctetsInDup;
unsigned long tcpOctetsRetrans;
unsigned long tcpInputPkts;
unsigned long tcpOutputPkts;
unsigned long tcpDupPkts;
unsigned long tcpRetransPkts;
}TCPStats;
/*===---------------===*/
/*=====================*/
/*===---------------===*/
typedef struct TCPCreatePB
{ // TCPCreate parameter block
Ptr rcvBuff; // Receive buffer
unsigned long rcvBuffLen; // Its size
TCPNotifyProc notifyProc; // Notify routine
Ptr userDataPtr; // Custom data
}TCPCreatePB;
/*===---------------===*/
typedef struct TCPOpenPB
{ // TCPActiveOpen and TCPPassiveOpen parameter block
byte ulpTimeoutValue; // Timeout span
byte ulpTimeoutAction; // What to do then?
byte validityFlags; // See above
byte commandTimeoutValue; //
ip_addr remoteHost; // Our target host
tcp_port remotePort; // Port we use for connection
ip_addr localHost; // Local machine
tcp_port localPort; // Local port for connection
byte tosFlags; // See above
byte precedence; //
Boolean dontFrag; // Don't fragment flag
byte timeToLive; // Time remaining to succeed
byte security; //
byte optionCnt; // Number of options to follow
byte options[40]; //
Ptr userDataPtr; // Custom data
}TCPOpenPB;
/*===---------------===*/
typedef struct TCPSendPB
{ // TCPSend parameter block
byte ulpTimeoutValue; // Timeout span
byte ulpTimeoutAction; // What to do then?
byte validityFlags; // See above
Boolean pushFlag; // Push data through?
Boolean urgentFlag; // Is this send urgent?
Ptr wdsPtr; // Write pointer
unsigned long sendFree; //
unsigned short sendLength; //
Ptr userDataPtr; // Custom data
}TCPSendPB;
/*===---------------===*/
typedef struct TCPReceivePB
{ // TCPRcv, TCPBrfReturn, and TCPNoCopyRcv parameter block
byte commandTimeoutValue; // Timeout span
byte filler; // Unneeded
Boolean markFlag; //
Boolean urgentFlag; // Urgent action?
Ptr rcvBuff; // Receive buffer
unsigned short rcvBuffLen; // Its length
Ptr rdsPtr; // Read pointer
unsigned short rdsLength; // Its length
unsigned short secondTimeStamp; //
Ptr userDataPtr; // Custom data
}TCPReceivePB;
/*===---------------===*/
typedef struct TCPClosePB
{ // TCPClose parameter block
byte ulpTimeoutValue; // Timeout span
byte ulpTimeoutAction; // What to do then?
byte validityFlags; // See above
Ptr userDataPtr; // Custom data
}TCPClosePB;
/*===---------------===*/
typedef struct TCPStatusPB
{ // TCPStatus parameter block
byte ulpTimeoutValue; // Timeout span
byte ulpTimeoutAction; // What to do then?
long unused;
ip_addr remoteHost; // Our target host
tcp_port remotePort; // Port we use for connection
ip_addr localHost; // Local machine
tcp_port localPort; // Local port for connection
byte tosFlags; // Type of service
byte precedence; //
byte connectionState; //
unsigned short sendWindow; // Communication windows
unsigned short rcvWindow; //
unsigned short amtUnackedData; // Amount of unacknowledged data
unsigned short amtUnreadData; // Amount of unread data
Ptr securityLevelPtr; //
unsigned long sendUnacked; // Send unacknowledged data
unsigned long sendNext; //
unsigned long congestionWindow; //
unsigned long rcvNext; //
unsigned long srtt; // Smoothed round-trip time (ms)
unsigned long lastRTT; // Last round-trip time (ms)
unsigned long sendMaxSegSize; // Largest segment we can send
struct TCPConnectionStats* connStatPtr; // Statistics block
Ptr userDataPtr; // Custom data
}TCPStatusPB;
/*===---------------===*/
typedef struct TCPAbortPB
{ // TCPAbort parameter block
Ptr userDataPtr; // Custom data
}TCPAbortPB;
/*===---------------===*/
typedef struct TCPGlobalInfoPB
{ // TCPGlobalInfo parameter block
struct TCPParam* tcpParamPtr; // Parameters
struct TCPStats* tcpStatsPtr; // Statistics
unsigned long* tcpCDBTable; //
Ptr userDataPtr; // Custom data
}TCPGlobalInfoPB;
/*===---------------===*/
typedef struct ipctlGetAddrPB
{
ip_addr ourAddress; // Local IP address
long ourNetMask; // Local IP network mask
}ipctlGetAddrPB;
/*===---------------===*/
typedef struct TCPiopb
{ // TCP parameter block
struct QElem* qLink; // Address of next queue element
short qType; // Always ioQType (2)
short ioTrap; // Used internally
Ptr ioCmdAddr; // Used internally
ProcPtr ioCompletion; // Completion routine
OSErr ioResult; // Result code
StringPtr ioNamePtr; // Used internally
short ioVRefNum; // Used internally
short ioCRefNum; //
short csCode; // Command code
StreamPtr tcpStream; // Our stream reference
union
{ // Specific tasks
TCPCreatePB create;
TCPOpenPB open;
TCPSendPB send;
TCPReceivePB receive;
TCPClosePB close;
TCPAbortPB abort;
TCPStatusPB status;
TCPGlobalInfoPB globalInfo;
} csParam;
}TCPiopb, *TCPiopbPtr;
/*===---------------===*/
typedef struct IPParamBlock
{ // TCP parameter block
struct QElem* qLink; // Address of next queue element
short qType; // Always ioQType (2)
short ioTrap; // Used internally
Ptr ioCmdAddr; // Used internally
ProcPtr ioCompletion; // Completion routine
OSErr ioResult; // Result code
StringPtr ioNamePtr; // Used internally
short ioVRefNum; // Used internally
short ioCRefNum; //
short csCode; // Command code
ip_addr ourAddress; // Local address
long outnetMask; // Local network mask
}IPParamBlock, *IPParamBlockPtr;
/*===---------------===*/
/*=====================*/
/*===---------------===*/
struct CTCP : CMacTCPDriver
Begin
protected:
ip_addr remoteAddress; // The IP address of the remote machine
ip_addr localAddress; // The IP address of the local machine
ip_port destinationPort; // The port number of the destination machine (usually zero)
ip_port sourcePort; // The port number of the local machine
char remoteHostName[kNameLength];//Ascii name of the destination machine
unsigned long streamID; // The connection ID for the stream
Size streamLength; // Length of the stream
Ptr streamBuffer; // Buffer for our stream
Ptr inBuffer; // The processed data
Ptr outBuffer; // The outgoing data
Size inDataLength; // How long the data is or can be
Size outDataLength; // The outgoing data length
Boolean fMark; // The mark flag
Boolean fUrgent; // The urgent flag
byte timeOutDelay; // The amount of time that should be spent waiting
public:
OSErr ITCP // Initialize this object
( void // No arguments
);
void Dispose // Get rid of our object
( void // No arguments
);
virtual OSErr Create // Creates a stream and data buffers
( void // No arguments
);
virtual OSErr PassiveOpen // Wait for a connection
( void // No arguments
);
virtual OSErr ActiveOpen // Initiate a connection
( void // No arguments
);
virtual OSErr Send // Send our data over the connection
( void // No arguments
);
virtual OSErr NoCopyRcv // Read received data directly
( Ptr rdsPtr, // Our read buffer
short rdsLength // How much to read
);
virtual OSErr BfrReturn // Return buffers after NoCopyRcv
( Ptr rdsPtr // Our read buffer
);
virtual OSErr Rcv // Read a copy of data received over our connection
( void // No arguments
);
virtual OSErr Close // No more data to send, does not break connection
( void // No arguments
);
virtual OSErr Abort // Terminate connection and disregard pending data
( void // No arguments
);
virtual OSErr Release // Close the TCP stream and release buffers
( void // No arguments
);
virtual OSErr Status // Fetch connection information
( TCPStatusPB* theStatus // The status record
);
virtual OSErr GlobalInfo // Collect global statistics and parameters
( TCPParam* tcpParam, // Parameter record
TCPStats* tcpStat // Statistics record
);
virtual ip_addr GetMyIPAddress // Fetches local IP#
( void // No arguments
);
virtual void MakeStreamBuffer // Set up a stream buffer (forget previous)
( Size length // Size of the buffer
);
virtual void PlaceData // Set up out-going data and buffer
( Ptr data, // Our data
Size length // Size of the data field
);
virtual void CreateInputBuffer // Set up in-coming data and buffer
( Ptr* data, // Our data buffer
Size length // Size of the data field
);
virtual OSErr SetInputBuffer // Set up in-coming data and buffer
( Ptr data, // Our data buffer
Size length // Size of the data field
);
virtual Size GetInputLength // Get size of the input buffer
( void // No arguments
);
virtual Ptr GetInputBuffer // Get the input buffer
( void // No arguments
);
virtual OSErr GetLastError // Get our last error
( void // No arguments
);
virtual void SetDestination // Set remote host parameters
( char* name, // Remote machine's name
ip_addr address, // Remote machine's address
ip_port port // Remote machine's port
);
virtual void GetDestination // Get remote host parameters
( char* name, // Remote machine's name
ip_addr* address, // Remote machine's address
ip_port* port // Remote machine's port
);
virtual void ReleaseStreamBuffer // Releases the stream buffer
( void // No arguments
);
virtual void ReleaseInputBuffer // Releases the input buffer
( void // No arguments
);
virtual void ReleaseOutputBuffer // Releases the output buffer
( void // No arguments
);
virtual void ReleaseBuffers // Releases all our buffer
( void // No arguments
);
virtual void SetTimeOut // Sets time out delay
( byte timeOut // The delay
);
virtual byte GetTimeOut // Gets time out delay
( void // No arguments
);
protected:
virtual void Wait // Waits...
( void // No arguments
);
virtual void SetSizeOfParameters // Sets the size of the parameter block
( void // No arguments
);
End;
/*===---------------===*/
/*=====================*/